﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class TPFSWTXT
    {
        #region ==VAPR===========
        public static readonly DependencyProperty VAPRProperty = DependencyProperty.Register("VAPR",
            typeof(string), typeof(TPFSWTXT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAPRChanged));
        public string VAPR
        {
            get
            {
                return (string)GetValue(VAPRProperty);
            }
            set
            {
                SetValue(VAPRProperty, value);
            }
        }
        private static void OnVAPRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPFSWTXT;
            if (src != null)
            {
                src.VAPR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==RS===========
        public static readonly DependencyProperty RSProperty = DependencyProperty.Register("RS",
            typeof(string), typeof(TPFSWTXT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRSChanged));
        public string RS
        {
            get
            {
                return (string)GetValue(RSProperty);
            }
            set
            {
                SetValue(RSProperty, value);
                OnExtInfoChg(value);
            }
        }
        private static void OnRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPFSWTXT;
            if (src != null)
            {
                src.RS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==JS===========
        public static readonly DependencyProperty JSProperty = DependencyProperty.Register("JS",
            typeof(string), typeof(TPFSWTXT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJSChanged));
        public string JS
        {
            get
            {
                return (string)GetValue(JSProperty);
            }
            set
            {
                SetValue(JSProperty, value);
                OnExtInfoChg(value);
            }
        }
        private static void OnJSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPFSWTXT;
            if (src != null)
            {
                src.JS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==ZZ===========
        public static readonly DependencyProperty ZZProperty = DependencyProperty.Register("ZZ",
            typeof(string), typeof(TPFSWTXT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnZZChanged));
        public string ZZ
        {
            get
            {
                return (string)GetValue(ZZProperty);
            }
            set
            {
                SetValue(ZZProperty, value);
                OnExtInfoChg(value);
            }
        }
        private static void OnZZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPFSWTXT;
            if (src != null)
            {
                src.ZZ = (string)e.NewValue;
            }
        }
        #endregion
        #region ==HZ===========
        public static readonly DependencyProperty HZProperty = DependencyProperty.Register("HZ",
            typeof(string), typeof(TPFSWTXT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHZChanged));
        public string HZ
        {
            get
            {
                return (string)GetValue(HZProperty);
            }
            set
            {
                SetValue(HZProperty, value);
                OnExtInfoChg(value);
            }
        }
        private static void OnHZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPFSWTXT;
            if (src != null)
            {
                src.HZ = (string)e.NewValue;
            }
        }
        #endregion

        #region ==CP===========
        public static readonly DependencyProperty CPProperty = DependencyProperty.Register("CP",
            typeof(string), typeof(TPFSWTXT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCPChanged));
        public string CP
        {
            get
            {
                return (string)GetValue(CPProperty);
            }
            set
            {
                SetValue(CPProperty, value);
                OnExtInfoChg(value);
            }
        }
        private static void OnCPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPFSWTXT;
            if (src != null)
            {
                src.CP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==SJ===========
        public static readonly DependencyProperty SJProperty = DependencyProperty.Register("SJ",
            typeof(string), typeof(TPFSWTXT),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSJChanged));
        public string SJ
        {
            get
            {
                return (string)GetValue(SJProperty);
            }
            set
            {
                SetValue(SJProperty, value);
                OnExtInfoChg(value);
            }
        }
        private static void OnSJChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TPFSWTXT;
            if (src != null)
            {
                src.SJ = (string)e.NewValue;
            }
        }
        #endregion


        public virtual void OnExtInfoChg(string value)
        {
            INFO = RS + JS + ZZ + HZ + CP + SJ;
        }
        public TPFSWTXT()
        {

            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVAART();
            this.DataContext = MV;
            InitializeComponent();
            ART = "S" + MV.year.Substring(3, 1) + "-0";
        }

        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (ART.Trim().Length < 3)
            {
                MessageBox.Show("条件太少,数据太多");
                return;
            }

            dwData = TBMain.NewRow();

            dwData["VAAMANDANT"] = app.Mandant;
            dwData["VAAKOLL"] = KOLL;
            dwData["VAAARTST"] = ARTST;
            dwData["VAAART"] = ART.Trim();
            dwData["VAABEZ"] = DES.Trim();
            dwData["VAADART"] = FARBE.Trim();
            SResult = TMV.QVA08(dwData);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
        }

       

        public void VAFCommand(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.VAFTXT(RUNID, KEY);

        }

        public override void OnCARTChg(string art)
        {

            if (art.Length < 21)
            {
                INFO = "";
                return;
            }
            ART = art.Substring(1, 20);
            QueryCommand(null, null);
            vwMaster.View.MoveCurrentToFirst();
            base.OnCARTChg(art);
        }
    }
}
